<?php

namespace app\model;

use think\Model;
use think\model\concern\SoftDelete;

class Order extends Model
{
    /**
     * Use Thinkphp ORM Model
     */
    use SoftDelete;
    protected $deleteTime = 'delete_time';
    protected $defaultSoftDelete = 0;
    protected $autoWriteTimestamp = 'int';


    /**
     * 查询订单支付状态
     */
    public static function payStatus($order_no)
    {
        return self::where('order_no', $order_no)->findOrEmpty()->toArray();
    }

    /**
     * 设置订单为已支付
     */
    public static function setOrderPaySuccess($order_no, $res_money = 0)
    {
        $order_info = self::where('order_no', $order_no)->findOrEmpty()->toArray();
        if(!empty($order_info))
        {
            self::update(['is_pay'=>1, 'payment_time'=>time(), 'pay_amount'=>$res_money],
                ['id'=>$order_info['id']]);
        }
    }
}